using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LoginPopupView : ViewBase
{
    Button loginGameBtn;
    Button registGameBtn;
    InputField usernameInput;
    InputField passwordInput;
    Text score;
    public override void Init(UIWindow uiBase)
    {
        Debug.Log("GameView Init");
        loginGameBtn = uiBase.transform.Find("StartBtn").GetComponent<Button>();
        registGameBtn = uiBase.transform.Find("RegistBtn").GetComponent<Button>();
        usernameInput = uiBase.transform.Find("usernameInput").GetComponent<InputField>();
        passwordInput = uiBase.transform.Find("passwordInput").GetComponent<InputField>();
        loginGameBtn.onClick.AddListener(() =>
        {
            string username = usernameInput.text;
            string password = passwordInput.text;

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                Debug.LogWarning("用户名或密码不能为空！");
                return;
            }
            (uiBase.control as LoginPopupControl).Login(username, password);
            
        });
        registGameBtn.onClick.AddListener(() =>
        {
            string username = usernameInput.text;
            string password = passwordInput.text;

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                Debug.LogWarning("用户名或密码不能为空！");
                return;
            }
            (uiBase.control as LoginPopupControl).Login(username, password);
            
        });
    }

    public override void OnEnable()
    {
        Debug.Log("GameView OnEnable");
    }

    public override void OnDestory()
    {
    }

    public override void Update()
    {
    }
}
